﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using DataControls;

namespace GiaoVien_QuanLy_DeTai
{
    public partial class KHOA_Form : Form
    {
        KHOA khoa = new KHOA();
        KHOA_Data khoa_Data = new KHOA_Data();
        
        public KHOA_Form()
        {
            InitializeComponent();
        }

        private void KHOA_Form_Load(object sender, EventArgs e)
        {
            txtMaKhoa.Text = "Khoa";
            txtTenKhoa.Text = "";
        }

        private void btnHienThi_Click(object sender, EventArgs e)
        {
            khoa.hienthi_Khoa(dtgKhoa);
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            if (txtMaKhoa.Text == "")
            {
                txtMaKhoa.Focus();
                MessageBox.Show("Ban chua dien ma so Khoa");
                return;
            }
            else if (txtTenKhoa.Text == "")
            {
                txtTenKhoa.Focus();
                MessageBox.Show("Ban chua dien ten Khoa");
                return;
            }

            else if (khoa_Data.kiemtra_MaKhoa(txtMaKhoa.Text.ToString()))
            {
                MessageBox.Show("Ban nhap trung Ma Khoa");
                txtMaKhoa.Focus();
                return;
            }
            else if (khoa_Data.kiemtra_TenKhoa(txtTenKhoa.Text.ToString()))
            {
                MessageBox.Show("Ban nhap trung Ten Khoa");
                txtTenKhoa.Focus();
                return;
            }

            else
            {
                khoa.maKhoa = txtMaKhoa.Text.ToString();
                khoa.tenKhoa = txtTenKhoa.Text.ToString();
                khoa.them_Khoa(khoa);
                khoa.hienthi_Khoa(dtgKhoa);

                txtMaKhoa.Text = "Khoa";
                txtTenKhoa.Text = "";
            }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (txtMaKhoa.Text == "")
            {
                txtMaKhoa.Focus();
                MessageBox.Show("Ban chua dien ma Khoa");
                return;
            }
            else if (khoa_Data.kiemtraMaKhoa_Lop(txtMaKhoa.Text.ToString()))
            {
                MessageBox.Show("Ban chua xoa Khoa trong Lop Hoc");
                return;
            }
            else if (khoa_Data.kiemtraMaKhoa_GV(txtMaKhoa.Text.ToString()))
            {
                MessageBox.Show("Ban chua xoa Khoa trong Giao Vien");
                return;
            }
            else
            {
                khoa.xoa_Khoa(txtMaKhoa.Text.ToString());
                khoa.hienthi_Khoa(dtgKhoa);

                txtMaKhoa.Text = "Khoa";
                txtTenKhoa.Text = "";
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            if (txtMaKhoa.Text == "")
            {
                txtMaKhoa.Focus();
                MessageBox.Show("Ban chua dien ma so Khoa");
                return;
            }
            else if (txtTenKhoa.Text == "")
            {
                txtTenKhoa.Focus();
                MessageBox.Show("Ban chua dien ten Khoa");
                return;
            }

            else
            {
                khoa.maKhoa = txtMaKhoa.Text.ToString();
                khoa.tenKhoa = txtTenKhoa.Text.ToString();
                khoa.sua_Khoa(khoa);
                khoa.hienthi_Khoa(dtgKhoa);

                txtMaKhoa.Text = "Khoa";
                txtTenKhoa.Text = "";
            }
        }

        private void dtgKhoa_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            dtgKhoa.AllowUserToAddRows = false;
            int dong = e.RowIndex;
            txtMaKhoa.Text = dtgKhoa.Rows[dong].Cells[0].Value.ToString();
            txtTenKhoa.Text = dtgKhoa.Rows[dong].Cells[1].Value.ToString();
        }

        private void txtMaKhoa_MouseClick(object sender, MouseEventArgs e)
        {
            txtMaKhoa.Text = "Khoa";
            txtTenKhoa.Text = "";
        }

       

     

       
    }
}
